package edu.guigu.appquickstart.activity;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import edu.guigu.appquickstart.R;
import edu.guigu.appquickstart.base.BaseActivity;

/**
* Activity相关基础入门知识
* @author Yuansir
* @since 2025/7/31 14:26
* @version V1.0
*/
public class AHomeActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ahome);

        // ActionBar设置
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle(R.string.title_activity_ahome);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        //
        findViewById(R.id.btn_life).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(AHomeActivity.this, "请查看日志", Toast.LENGTH_SHORT).show();
            }
        });
    }

    // 创建菜单
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_ahome,menu);

        return super.onCreateOptionsMenu(menu);
    }

    // 菜单选中
    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if(item.getItemId() == android.R.id.home){
            finish();
        }
        if(item.getItemId() == R.id.menu_add){
            Toast.makeText(this, "添加", Toast.LENGTH_SHORT).show();
        }
        if(item.getItemId() == R.id.menu_setting){
            Toast.makeText(this, "设置", Toast.LENGTH_SHORT).show();
        }
        return super.onOptionsItemSelected(item);
    }
}